<template>
<div>
    <validator name='v'>
        <a href="#" class="btn btn-primary" @click="this.$back('items')">&lt;&lt;</a>
        <form novalidate class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-2 control-lable">审核人：</label>
                <div class="col-sm-8">
                    <input readonly='readonly' class="form-control" type="text" v-model="item.f_repair_approved_by" v-validate:f_repair_approved_by='{ required: true }' />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-lable">审核结果：</label>
                <div class="col-sm-8">
                    <input readonly='readonly' class="form-control" type="text" v-model="item.f_repair_approved" v-validate:f_repair_approved='{ required: true }' />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-lable">审核时间：</label>
                <div class="col-sm-8">
                    <input readonly='readonly' class="form-control" type="text" v-model="item.f_repair_approved_time"/>
                </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-lable">审核备注：</label>
              <div class="col-sm-8">
                  <textarea class="form-control" type="text" v-model="item.f_repair_approved_note"></textarea>
              </div>
          </div>
            <div class="form-group col-sm-12">
              <button :disabled="item.f_repair_approved != '未审核' && item.f_repair_approved != '重修'" type="button" class="btn btn-primary col-sm-3" @click="approve">
                 <span class="glyphicon glyphicon-ok"></span> 通过
              </button>
              <button :disabled="item.f_repair_approved != '未审核' && item.f_repair_approved != '重修'" type="button" class="btn btn-primary col-sm-3" @click="disapprove">
                 <span class="glyphicon glyphicon-remove"></span> 打回
              </button>
            </div>
        </form>
    </validator>
</div>

</template>

<script>
import * as Util from '../Util'
import co from 'co'
import Vue from 'vue'

let syncVerify = function * (self) {
  yield self.$post('rs/logic/审核维修单', {data:{item: self.item}}, {resolveMsg: '操作成功！', rejectMsg: '操作失败！'})
}

export default {
  title: '维修审核',
  props: ['item', 'name'],
  ready () {
    if(this.item.f_repair_approved == '未审核') {
      this.item.f_repair_approved_time = Util.toStandardTimeString()
      this.item.f_repair_approved_by = this.name
    }
  },
  methods: {
    approve () {
      this.item.f_repair_approved = '已审核'
      let gen = syncVerify(this)
      return co(gen)
    },
    disapprove () {
      this.item.f_repair_approved = '打回'
      let gen = syncVerify(this)
      return co(gen)
    },
  }
}

</script>
